package userclasses;

import java.util.Hashtable;

/**
 *
 * @author Daniel Lingenfelter
 */
public class SystemConnect {
    Hashtable[] PassListHash;
    Hashtable[] PickUpHash;
    Hashtable[] DropOffHash;

    PassOp[] PassOpArray = new PassOp[] {
            new PassOp("1 - 4 (One Vehicle)", 1, true),
            new PassOp("5 - 8 (Two Vehicles)", 2, false)
    };

    Station[] PickUpArray = new Station[] {
            new Station("Find Me (GPS)", 1, true),
            new Station("Station 1", 2, false),
            new Station("Station 2", 3, false)
    };

    Station[] DropOffArray = new Station[] {
            new Station("Let Me Choose (Map)", 1, true),
            new Station("Station 1", 2, false),
            new Station("Station 2", 3, true)
    };

    boolean e;
    String systemMessage, passSelected, pickSelected, dropSelected;
    int passValue, pickValue, dropValue;

    void connect(){
        //connect and login then retrieve list info.
        e = false;
        systemMessage = "";
        //initialize once info received.
        PassListHash = generatePassHash(PassOpArray);
        PickUpHash = generateStationHash(PickUpArray);
        DropOffHash = generateStationHash(DropOffArray);
        findInitialValues();
    }

    void setPassSelection (PassOp[] a){
        for(int i=0; i<a.length; i++){
            if(a[i].selected){
                passSelected = a[i].text;
            }
        }
    }

    void setPickStationSelection (Station[] a){
        for(int i=0; i<a.length; i++){
            if(a[i].selected){
                pickSelected = a[i].text;
            }
        }
    }
    
    void setDropStationSelection (Station[] a){
        for(int i=0; i<a.length; i++){
            if(a[i].selected){
                dropSelected = a[i].text;
            }
        }
    }

    void setPassOption (PassOp[] a, int sel){
        for(int i=0; i<a.length; i++){
            if(a[i].selected){
                a[i].selected = false;
            }
        }
        a[sel].selected = true;
        passValue = a[sel].value;
        setPassSelection(a);
    }

    void setPickStationOption (Station[] a, int sel){
        for(int i=0; i<a.length; i++){
            if(a[i].selected){
                a[i].selected = false;
            }
        }
        a[sel].selected = true;
        pickValue = a[sel].value;
        setPickStationSelection(a);
    }

    void setDropStationOption (Station[] a, int sel){
        for(int i=0; i<a.length; i++){
            if(a[i].selected){
                a[i].selected = false;
            }
        }
        a[sel].selected = true;
        dropValue = a[sel].value;
        setDropStationSelection(a);
    }

    private Hashtable[] generatePassHash(PassOp[] a) {
        int length = a.length;
        Hashtable[] data = new Hashtable[length];
        for(int i = 0; i < length; i++){
               data[i] = new Hashtable();
               data[i].put("Label", a[i].text);
        }
        return data;
    }

    private Hashtable[] generateStationHash(Station[] a) {
        int length = a.length;
        Hashtable[] data = new Hashtable[length];
        for(int i = 0; i < length; i++){
               data[i] = new Hashtable();
               data[i].put("Label", a[i].text);
        }
        return data;
    }

    private void findInitialValues(){
        for(int i=0; i<PassOpArray.length; i++){
            if(PassOpArray[i].selected){
                passValue = PassOpArray[i].value;
                passSelected = PassOpArray[i].text;
            }
        }
        for(int i=0; i<PickUpArray.length; i++){
            if(PickUpArray[i].selected){
                pickValue = PickUpArray[i].value;
                pickSelected = PickUpArray[i].text;
            }
        }
        for(int i=0; i<DropOffArray.length; i++){
            if(DropOffArray[i].selected){
                dropValue = DropOffArray[i].value;
                dropSelected = DropOffArray[i].text;
            }
        }
    }
}